package org.example;


import com.scy.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * https://cloud.tencent.com/developer/article/1165617
 * MDC ( Mapped Diagnostic Context，映射调试上下文 )
 * 是 log4j 和 logback 提供的一种方便在多线程条件下记录日志的功能
 */
public class AppLog4j {

    private static final Logger logger = LoggerFactory.getLogger(AppLog4j.class);
    private static final Logger logger2 = LoggerFactory.getLogger("org.example");


    public static void main(String[] args) {

        for (int i = 0; i < 3; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    MDC.clear();
                    String traceId = UUID.randomUUID().toString().replaceAll("-", "");

                    MDC.put("mdc_id", traceId);
                    MDC.put("siteName", "北京");
                    logger.debug("测试MDC打印一");

                    MDC.put("siteName", "上海");
                    logger.info("测试MDC打印二");
                    TraceLogger.info("测试traceLogger打印二");

                    MDC.put("siteName", "深证");
                    logger.error("测试MDC打印三",new RuntimeException("出现异常"));

                    Utils.method1(Thread.currentThread().getName());
                }
            },"Thread_"+i).start();
        }

        System.out.println("程序结束了.请查看");
    }
}
